<!DOCTYPE html>
<html lang="en" class="no-js" xmlns:th="http://www.thymeleaf.org"
	xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout"
	layout:decorator="layout">
<head>
<title>促销标题管理</title>
<style> 

  .white_content {  
  display: none;  position: absolute;  top: 25%;  left: 25%;  width: 50%;  height: 50%;  padding: 16px;  
  border: 16px solid bule;  background-color: white;  z-index:1002;  overflow: auto;  
  } 
  ul { list-style:none;
	} 
	
</style> 
</head>
<body id="check_goodsSN_form">
<div layout:fragment="content">
<link th:href="@{/plugins/bootstrap-modal/css/bootstrap-modal-bs3patch.css}" rel="stylesheet" href="plugins/bootstrap-modal/css/bootstrap-modal-bs3patch.css"/>
<link th:href="@{/plugins/bootstrap-modal/css/bootstrap-modal.css}" rel="stylesheet" href="plugins/bootstrap-modal/css/bootstrap-modal.css"/>
<link th:href="@{/plugins/zTree/css/zTreeStyle/zTreeStyle.css}" rel="stylesheet" href="plugins/zTree/css/zTreeStyle/zTreeStyle.css"/>
<script th:src="@{/plugins/zTree/js/jquery.ztree.core-3.5.js}" src="plugins/zTree/js/jquery.ztree.core-3.5.js" type="text/javascript"></script>	

		<div class="row">
			<div class="col-md-12">
				<div class="btn-group pull-right">
					<a href="index.html" th:href="@{/goods/goods/index}"
						id="Link_cancel" class="btn green">返回<i
						class="fa fa-arrow-circle-o-left"></i></a>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-md-12">
				<div class="form">
					<form role="form" th:action="@{/goods/goods/editTitleByConditions}" id="goods_form_check" name="theForm"
						th:object="${goods}" method="post" class="form-horizontal">
						<h4 class="form-section">促销标题管理</h4>
					
						<div class="form-body">
							<div class="form-group" th:class="${#fields.hasErrors('brandId')}? 'form-group has-error' : 'form-group'">
								<label class="control-label col-md-3">品牌名称<span class="required" aria-required="true">* </span></label>
								<div class="col-md-4">
									<select id="selt_brandType" name="selt_brandType"  th:remove="none" class="form-control" th:field="*{brandId}" >
										<option th:value="0">全部品牌</option>
										<option th:each="eachValue : ${brands}"   th:value="${eachValue.id}" th:text="${eachValue.name}"></option>
									</select>
									<span class="help-block" th:if="${#fields.hasErrors('brandId')}" th:errors="*{brandId}">商品名称不能为空</span>
								</div>
							</div>

							
						<div class="form-group" th:class="${#fields.hasErrors('categoryId')}? 'form-group has-error' : 'form-group'">
							<label class="control-label col-md-3">商品分类<span class="required" aria-required="true">* </span></label>
							<div class="col-md-4" id="categoryCheck0">
								
					            <select th:field="*{categoryId}" th:remove="all-but-first" class="form-control"  style="display:none;" >
					                <option th:each="eachValue : ${ourcategorys}" th:value="${eachValue.id}" th:text="${eachValue.name}"  style="display:none" ></option>
					            </select>
								
								<button id="treebutton0" class="btn btn-default dropdown-toggle" type="button"  data-toggle="dropdown">
									分类 <i class="fa fa-angle-down"></i>
								</button>
								<div class="dropdown-menu dropdown-content input-large">
									<div id="category_tree0" role="menu">
									</div>
								</div>

 					            <span class="help-block" th:if="${#fields.hasErrors('categoryId')}" th:errors="*{categoryId}">顶级分类不可以修改</span>
										
							</div>
							</div>
							<div class="form-group" >
								<label class="control-label col-md-3">促销标题<span class="required" aria-required="true">* </span></label>
								<div class="col-md-4">
									<input type="text" class="form-control" placeholder="促销标题" th:field="*{title}"  id="goods_title" />
								</div>
							</div>
						
						
						
						<div class="form-actions fluid">
							<div class="col-md-offset-3 col-md-9">
								<button type="button" class="btn blue" id="bt_submitSKU" name="button_submit" onclick="editTitleByBrandAndType()">提交并设置SKU</button>
								<button type="button" class="btn blue" id="bt_submit" name="button_submit" onclick="editTitleByBrandAndType()">提交</button>
							</div>
						</div>
						</div>
						
					</form>
					
					
					<hr class="form-section"/>
					
					
					
						<!-- <input type="hidden" name="goodsIds" id="goods_id_text_hidden"/>	 -->				
							

							  <div class="row" >
						            <div style="padding-left: 10px;" class="col-md-12">
						                <div th:replace="support/searchGoods :: search_form"></div>
						            </div>
						            <div class="col-md-12">
						                <div class="form">
						                    <div class="form-body">
						                        <div th:replace="support/searchGoods :: search_list"></div>
						                    </div>
						                </div>
						            </div>
						        </div>
						        <form role="form" th:action="@{/goods/goods/editTitleByConditions}" id="goods_title_ids" name="theForm"
							       th:object="${goods}" method="post" class="form-horizontal"> 
										<input type="hidden" th:field="*{goodsSizeIds}" id="goods_id_text_hidden"/> 
										<div class="form-body">
											 	<div class="form-group" >
												<label class="control-label col-md-3">促销标题<span class="required" aria-required="true">* </span></label>
												<div class="col-md-4">
													<input type="text" class="form-control" placeholder="促销标题" th:field="*{title}"   id="goods_title" />
												</div>
												</div> 
												<div class="form-actions fluid">
													<div class="col-md-offset-3 col-md-9">
														<button type="button" class="btn blue" id="" name="button_submit" onclick="editTitleByGoodsId()">提交</button>
													</div>
												</div>
												</div>
											
									 </form>  
				<!-- 			 style="display:none"		 -->
									
								</div>
							</div>
							
						
						</div>	
					</div>
</body>
</html>


<script th:inline="javascript">
	/*<![CDATA[*/
	  
	KindEditor.ready(function(K) {
		K.create('#textarea_content', {
			uploadJson : '/upload/GOODS',
			allowFileManager : false
		});
	});
	var _ztree=$('#category_tree0').jstree({
        "core" : {
            'data' : {'url' : function (node) {return '/tree/category';}}
        }
    });
	    $('#category_tree0').on('select_node.jstree', function(e,data) { 
	    	$("#categoryId option").each(function() { this.selected = (this.value == data.node.id); });
	    	$("#categoryId").change();
    		$("#tree_modal").modal('hide');
	    });
	
	
	    var result;
	    function getCategoryById(id,categories){   	
	    	$(categories).each(function() { 
	    		if(this.id == id)result = this; 
	    		console.log(this.id);
		    	if(result){
		    		console.log('find it' + result);
		    		return result;
		    	}else{
		    		console.log('not find ,try sub cat' + result);
		    		result = getCategoryById(id,this.children);
		    		return result;
		    	}
	    	});
			return result;
	    }
	    function check2(checkId){
	    	var currentId = $("#categoryId").val();
			if($("#id").val() == 0){
				return true;
			}
	    	var thisCategory = getCategoryById(checkId,$('#category_tree0').jstree().get_json()[0].children);
	    	var thisSubCategories = [];
	    	//console.log(thisCategory);
	    	addSubCategoriesToArray(thisCategory,thisSubCategories);
	    	//console.log(thisSubCategories);
	    	
	    	var checkPassed = true;
	    	$(thisSubCategories).each(function() {
	    		if(currentId == this){
	    			alert("不能选择自身子类");
	    			checkPassed = false;
	    		}
	    	});
	    	
	    	return checkPassed;
	    }
	    function addSubCategoriesToArray(category,array){
	    	//console.log(category.children);
	    	if(category.children){
		    	$(category.children).each(function() {
		    		console.log(this);
		    		array[array.length] = this.id;	 
		    		console.log(this.children);   		
		    		if(this.children)addSubCategoriesToArray(this.children,array);
		    	});
	    	}
	    }
	
	
	function handleAutoThumb(checked)
	{
	    document.forms['theForm'].elements['thumbPic'].disabled = checked;
	}

	function editTitleByBrandAndType(){
		$("#goods_form_check").submit();
	}
	
	function editTitleByGoodsId(){
		var goodsId =  getSelectedGoodsIds();
		if(goodsId == ''){
			alert("没做任何更改，无法提交");
			return;
		}
		$("#goods_id_text_hidden").attr("value",goodsId);
		$("#goods_title_ids").submit();
	}
	
	$(document).ready(function(){
		/* $("input[name='goodsColorIdList']:checked").click();
		$("input[name='goodsSizeIdList']:checked").click(); */
	//alert($("input[name='goodsColorIdList']:checked").length);
		if($("input[name='goodsColorIdList']:checked").length >0 || $("input[name='goodsSizeIdList']:checked").length >0){
			$("#bt_submit").hide();
	    	$("#bt_submitSKU").show();
	    	
		}else{
			$("#bt_submit").show();
	    	$("#bt_submitSKU").hide();
		}
		 /* if($("#attrMapOneColor").val() != null){
		    	$("#bt_submit").hide();
		    	$("#bt_submitSKU").show();
		    }else{
		    	$("#bt_submitSKU").hide();
		    	$("#bt_submit").show();
		    } */
		
		$('#treebutton0').html($("#categoryId").find("option:selected").text() + '<i class="fa fa-angle-down"></i>');
		$("#categoryId").change(function(){$('#treebutton0').html($("#categoryId").find("option:selected").text() + '<i class="fa fa-angle-down"></i>'); });
		
			$(".div_contentlist span").trigger("change");
		
    	
		if($("#checkVal").attr("checked")=="checked"){
			document.forms['theForm'].elements['thumbPic'].disabled = true;
		}



		 $("#goods_form_check").validate({
	         rules:{
	             title:{
	            	 maxlength:200 
	             },
	             goodsSN:{
	            	 required:true,
					 remote:{
							url:'/goods/goods/verifyGoodsSN?goodsId='+$('#goodsId').val(),
						},
					maxlength:10	
	             }
	             
	             
	         },
	         messages:{
	             title:{
	                 maxlength:'促销标题长度不可超过200'
	             }
	         }
	     });
		 
		 $("#goods_title_ids").validate({
	         rules:{
	             title:{
	            	 maxlength:200 
	             },
	             goodsSN:{
	            	 required:true,
					 remote:{
							url:'/goods/goods/verifyGoodsSN?goodsId='+$('#goodsId').val(),
						},
					maxlength:10	
	             }
	             
	             
	         },
	         messages:{
	             title:{
	                 maxlength:'促销标题长度不可超过200'
	             }
	         }
	     });

		 
		 
		$("#sku_list_goodsAttrList td").each(function(i){
		 		$(".imgShow"+i).attr("src",$(this).html()); 
   		});
		
		$("#sku_list_checkBoxList td").each(function(j,checktx){
		$(".div_contentlist input[type=checkbox]:checked").each(function (i,item) {
			if(i == j){
				$("."+item.id).attr("type","text");
				$("."+item.id).attr("value",$(checktx).html());
			}
   		}); 
				
		});
		 
		$("#sku_list_SelectList td").each(function(i){
			$(".slelect_checked option[value='"+$(this).html()+"']").attr("selected", "selected");
		});
		 

	});

	/*]]>*/
</script>